let mysql = require('mysql');

function select(sql) {
  let promise = new Promise((resolve, reject) => {
    let result = null;
    let connection = mysql.createConnection({
      host: 'localhost',
      user: 'root',
      password: 'zt4945327',
      database: 'test',
    });

    connection.connect();
    connection.query(sql, (err, results,fields) => {
      if (err) {
        reject(err);
      } else {
        if (results.length > 0) {
          resolve(results);
        } else {
          resolve({ status: 0 });
        }
      }
    });
    connection.end();
  });
  
  return promise;
}

module.exports = select;
